package com.egao.api.controller.system;


import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
import com.egao.common.system.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * api登录相关接口
 * Created by wangfan on 2019-05-29 下午 3:43.
 * http://localhost/swagger-ui.html
 */
@RequestMapping("/api/menu")
@RestController
@Api(value = "菜单",tags = {"菜单"})
public class ApiMenuController extends BaseController {

    @Autowired
    private UserService userService;

    /**
     * 修改个人信息
     */
    @PostMapping("/getMenuList")
    @ApiOperation(value = "左侧菜单",notes = "",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",value = "账号",paramType = "body",dataType = "String",required = true),
            @ApiImplicitParam(name = "password",value = "用户名称",paramType = "body",dataType = "String",required = true)
    })
    public JsonResult updateMyInfo(User user, HttpServletRequest request) {
        user.setUserId(Integer.valueOf(getLoginUserId()));
        if (userService.getById(user) != null) {
            User newUser = userService.getById(user);
            newUser.setPassword(null);
            return JsonResult.ok("修改成功").put("data", newUser);
        }
        return JsonResult.error("修改失败");
    }

}
